package hr.dario.fragments;

import hr.dario.fragments.data.DataBaseAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity{

	private DataBaseAdapter mDbHelper;

	private EditText mNameText;
	private EditText mDescText;
	private Long mRowId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mDbHelper = new DataBaseAdapter(this);
		mDbHelper.open();

		setContentView(R.layout.location_edit);
		setTitle(R.string.edit_location);

		mNameText = (EditText) findViewById(R.id.loc_name);
		mDescText = (EditText) findViewById(R.id.loc_desc);

		Button confirmButton = (Button) findViewById(R.id.confirm);

		confirmButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View view) {
				String locName = mNameText.getText().toString();
				String locDesc = mDescText.getText().toString();
				
				long id = mDbHelper.createInput(DataBaseAdapter.DATABASE_TABLE_LOC,
						locName, locDesc);
				System.out.println(""+id);
				mNameText.setText("");
				mDescText.setText("");
				
				Toast.makeText(MainActivity.this, "Input made",
						Toast.LENGTH_SHORT).show();
			}
		});
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.option_menu, menu);
		return true;
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case R.id.item1:
			Intent i = new Intent(this, LocationsActivity.class);
			startActivity(i);
			return true;
		
		}

		return super.onMenuItemSelected(featureId, item);
	}

	
}
